package vn.edu.saigontech.ncms.service.impl;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import vn.edu.saigontech.ncms.model.user.Site;
import vn.edu.saigontech.ncms.service.SiteService;

@SuppressWarnings("unchecked")
public class SiteServiceImpl extends HibernateGenericService<Site, Long>
		implements SiteService {

	@Override
	public Collection<Site> findAll() {
		Criteria criteria = this.createCriteria();
		criteria.addOrder(Order.asc("name"));
		return criteria.list();
	}

	@Override
	public Site findByName(String name) {
		Criteria criteria = this.createCriteria();
		criteria.add(Restrictions.eq("name", name));
		return (Site) criteria.uniqueResult();
	}

	@Override
	public Set<Site> find(Long[] ids) {
		Set<Site> sites = new HashSet<Site>();
		for (Long id : ids) {
			sites.add(this.findById(id));
		}
		return sites;
	}
}